from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
time.sleep(1)

# element 单个元素
# print(driver.find_element_by_tag_name('input').get_attribute('outerHTML'))

# elements 多个元素
# list_input = driver.find_elements_by_tag_name('input')
# for i in list_input:
#     print(i.get_attribute('outerHTML'))

# 定位方式1-6
# id
# print(driver.find_element_by_id('kw').get_attribute('outerHTML'))

# class
# print(driver.find_element_by_class_name('s_ipt').get_attribute('outerHTML'))

# link_text
# print(driver.find_element_by_link_text('新闻').get_attribute('outerHTML'))
# partial_link_text
# print(driver.find_element_by_partial_link_text('新').get_attribute('outerHTML'))

# name
# print(driver.find_element_by_name('f').get_attribute('outerHTML'))
# tag_name
# print(driver.find_element_by_tag_name('input').get_attribute('outerHTML'))

# css_selector 标题.类属性
# print(driver.find_element_by_css_selector('div.s-p-top').get_attribute('outerHTML'))

# css 标题#iD
# print(driver.find_element_by_css_selector('div#s-top-left').get_attribute('outerHTML'))
# print(driver.find_element_by_css_selector('*').get_attribute('outerHTML'))



# print(driver.find_element_by_css_selector('span').get_attribute('outerHTML'))
# print(driver.find_element_by_css_selector('body>textarea').get_attribute('outerHTML'))

# css nth-child(4)第几个子类
# print(driver.find_element_by_css_selector('body>textarea:nth-child(4)').get_attribute('outerHTML'))

print(driver.find_element_by_css_selector('[id="kw"]').get_attribute('outerHTML'))






driver.quit()